/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package form;

import io.resource.ResourceDelegate;

/**
 *
 * @author Robert A. Cherry
 */
public class ApplicationSettingsEditor extends javax.swing.JDialog {

    // Variable Declaration
    // Project Classes
    private ResourceDelegate delegate;
    // End of Variable Declaration

    /**
     * Creates new form ApplicationSettingsEditor
     */
    public ApplicationSettingsEditor(java.awt.Frame parent, ResourceDelegate delegate, boolean modal) {
        super(parent, modal);
        initComponents();

        // Set values
        this.delegate = delegate;

        // Initialize
        init();
    }

    private void init() {

        // Setup controls
        // filetypeJField.setText(ResourceWriter.getInformalResourceTypes());

        // Set default selected
        scanJRadioButton.setSelected(delegate.getScanMode() == ResourceDelegate.SCAN_UNBIASED);
        importJRadioButton.setSelected(!scanJRadioButton.isSelected());

        //
        packageJCheckBox.setSelected(delegate.isLoadingPackages());
        generateEIDJCheckBox.setSelected(delegate.isGeneratingEditorIds());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        importButtonGroup = new javax.swing.ButtonGroup();
        mainJTabbedPane = new javax.swing.JTabbedPane();
        generalJPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        generateEIDJCheckBox = new javax.swing.JCheckBox();
        resourceJPanel = new javax.swing.JPanel();
        importJPanel = new javax.swing.JPanel();
        scanJRadioButton = new javax.swing.JRadioButton();
        importJRadioButton = new javax.swing.JRadioButton();
        filetypeJLabel = new javax.swing.JLabel();
        filetypeJField = new javax.swing.JTextField();
        packageJCheckBox = new javax.swing.JCheckBox();
        pictureJCheckBox = new javax.swing.JCheckBox();
        databaseJPanel = new javax.swing.JPanel();
        toolJPanel = new javax.swing.JPanel();
        databaseImportJCheckBox = new javax.swing.JCheckBox();
        databaseSupportJLabel = new javax.swing.JLabel();
        databaseJComboBox = new javax.swing.JComboBox();
        connectionJButton = new javax.swing.JButton();
        connectionJCheckBox = new javax.swing.JCheckBox();
        dataJButton = new javax.swing.JButton();
        buttonJPanel = new javax.swing.JPanel();
        defaultJButton = new javax.swing.JButton();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        applyJButton = new javax.swing.JButton();
        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(8, 0), new java.awt.Dimension(8, 0), new java.awt.Dimension(8, 32767));
        closeJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Options");
        setMinimumSize(new java.awt.Dimension(465, 272));
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Editor Options"));
        java.awt.GridBagLayout jPanel1Layout = new java.awt.GridBagLayout();
        jPanel1Layout.columnWidths = new int[] {0};
        jPanel1Layout.rowHeights = new int[] {0, 4, 0};
        jPanel1.setLayout(jPanel1Layout);

        generateEIDJCheckBox.setText("(Auto) Generate Editor Identification Tags");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        jPanel1.add(generateEIDJCheckBox, gridBagConstraints);

        javax.swing.GroupLayout generalJPanelLayout = new javax.swing.GroupLayout(generalJPanel);
        generalJPanel.setLayout(generalJPanelLayout);
        generalJPanelLayout.setHorizontalGroup(
            generalJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(188, Short.MAX_VALUE))
        );
        generalJPanelLayout.setVerticalGroup(
            generalJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(124, Short.MAX_VALUE))
        );

        mainJTabbedPane.addTab("General Settings", generalJPanel);

        importJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Resource Import Method"));

        importButtonGroup.add(scanJRadioButton);
        scanJRadioButton.setText("Scan Directory Folder");

        importButtonGroup.add(importJRadioButton);
        importJRadioButton.setText("Use Data Importing (Archive must include manifest)");

        filetypeJLabel.setText("Accepted Files Types (Separate with comma):");
        filetypeJLabel.setMaximumSize(new java.awt.Dimension(105, 20));
        filetypeJLabel.setMinimumSize(new java.awt.Dimension(105, 20));
        filetypeJLabel.setPreferredSize(new java.awt.Dimension(105, 20));

        filetypeJField.setEditable(false);
        filetypeJField.setEnabled(false);

        javax.swing.GroupLayout importJPanelLayout = new javax.swing.GroupLayout(importJPanel);
        importJPanel.setLayout(importJPanelLayout);
        importJPanelLayout.setHorizontalGroup(
            importJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(filetypeJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(scanJRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(importJRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(filetypeJField))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        importJPanelLayout.setVerticalGroup(
            importJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scanJRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(importJRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(filetypeJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filetypeJField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        packageJCheckBox.setText("Include Data Packages in scan");

        pictureJCheckBox.setText("Load Image Folder");

        javax.swing.GroupLayout resourceJPanelLayout = new javax.swing.GroupLayout(resourceJPanel);
        resourceJPanel.setLayout(resourceJPanelLayout);
        resourceJPanelLayout.setHorizontalGroup(
            resourceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resourceJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resourceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(resourceJPanelLayout.createSequentialGroup()
                        .addComponent(packageJCheckBox)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(resourceJPanelLayout.createSequentialGroup()
                        .addComponent(importJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(pictureJCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        resourceJPanelLayout.setVerticalGroup(
            resourceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resourceJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resourceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(importJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pictureJCheckBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(packageJCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainJTabbedPane.addTab("Resource Importing", resourceJPanel);

        toolJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("External Resources"));

        databaseImportJCheckBox.setText("Game Imports data from existing Database");
        databaseImportJCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                databaseImportJCheckBoxItemStateChanged(evt);
            }
        });

        databaseSupportJLabel.setText("Supported Database Tools:");

        databaseJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        databaseJComboBox.setEnabled(false);

        connectionJButton.setText("Setup Connection");
        connectionJButton.setEnabled(false);
        connectionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectionJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout toolJPanelLayout = new javax.swing.GroupLayout(toolJPanel);
        toolJPanel.setLayout(toolJPanelLayout);
        toolJPanelLayout.setHorizontalGroup(
            toolJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(toolJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(databaseImportJCheckBox)
                    .addGroup(toolJPanelLayout.createSequentialGroup()
                        .addComponent(databaseSupportJLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(databaseJComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, toolJPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(connectionJButton)
                .addContainerGap())
        );
        toolJPanelLayout.setVerticalGroup(
            toolJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(databaseImportJCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(toolJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(databaseSupportJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(databaseJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(connectionJButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        connectionJCheckBox.setText("Save Connection Information (Encrypted)");
        connectionJCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                connectionJCheckBoxItemStateChanged(evt);
            }
        });

        dataJButton.setText("View Raw Data");
        dataJButton.setEnabled(false);

        javax.swing.GroupLayout databaseJPanelLayout = new javax.swing.GroupLayout(databaseJPanel);
        databaseJPanel.setLayout(databaseJPanelLayout);
        databaseJPanelLayout.setHorizontalGroup(
            databaseJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(databaseJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(databaseJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(databaseJPanelLayout.createSequentialGroup()
                        .addComponent(toolJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(dataJButton, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
                    .addGroup(databaseJPanelLayout.createSequentialGroup()
                        .addComponent(connectionJCheckBox)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        databaseJPanelLayout.setVerticalGroup(
            databaseJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(databaseJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(databaseJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(toolJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dataJButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(connectionJCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainJTabbedPane.addTab("Database Connection", databaseJPanel);

        buttonJPanel.setLayout(new javax.swing.BoxLayout(buttonJPanel, javax.swing.BoxLayout.LINE_AXIS));

        defaultJButton.setText("Default");
        defaultJButton.setMaximumSize(new java.awt.Dimension(88, 26));
        defaultJButton.setMinimumSize(new java.awt.Dimension(88, 26));
        defaultJButton.setPreferredSize(new java.awt.Dimension(88, 26));
        defaultJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultJButtonActionPerformed(evt);
            }
        });
        buttonJPanel.add(defaultJButton);
        buttonJPanel.add(filler1);

        applyJButton.setText("Apply");
        applyJButton.setMaximumSize(new java.awt.Dimension(88, 26));
        applyJButton.setMinimumSize(new java.awt.Dimension(88, 26));
        applyJButton.setPreferredSize(new java.awt.Dimension(88, 26));
        applyJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyJButtonActionPerformed(evt);
            }
        });
        buttonJPanel.add(applyJButton);
        buttonJPanel.add(filler2);

        closeJButton.setText("Close");
        closeJButton.setMaximumSize(new java.awt.Dimension(88, 26));
        closeJButton.setMinimumSize(new java.awt.Dimension(88, 26));
        closeJButton.setPreferredSize(new java.awt.Dimension(88, 26));
        closeJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeJButtonActionPerformed(evt);
            }
        });
        buttonJPanel.add(closeJButton);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(mainJTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainJTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void databaseImportJCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_databaseImportJCheckBoxItemStateChanged

        // Dis / Enable databaseJComboBox
        databaseJComboBox.setEnabled(databaseImportJCheckBox.isSelected());
    }//GEN-LAST:event_databaseImportJCheckBoxItemStateChanged

    private void connectionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectionJButtonActionPerformed
        
        // Show connection dialog -- will reimplement in next version hopefully
    }//GEN-LAST:event_connectionJButtonActionPerformed

    private void connectionJCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_connectionJCheckBoxItemStateChanged
        
        // Ask user for a key to encrypt the information with -- soon
    }//GEN-LAST:event_connectionJCheckBoxItemStateChanged

    private void closeJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeJButtonActionPerformed

        // Close this dialog
        setVisible(false);
    }//GEN-LAST:event_closeJButtonActionPerformed

    private void applyJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyJButtonActionPerformed

        // Accept or deny data packages when doing a resource scan
        delegate.setLoadPackages(packageJCheckBox.isSelected());
        delegate.setLoadImages(pictureJCheckBox.isSelected());

        // TODO add your handling code here:
        delegate.setGenerateEditorIds(generateEIDJCheckBox.isSelected());

        //
        if (importJRadioButton.isSelected()) {

            // Change the scan mode
            delegate.setScanMode(ResourceDelegate.SCAN_BIASED);
        } else if (scanJRadioButton.isSelected()) {
            
            //
            delegate.setScanMode(ResourceDelegate.SCAN_UNBIASED);
        }
        
        // Loading Image Folder
        if (pictureJCheckBox.isSelected()) {
            
            //
            delegate.loadLooseImages();
        }
    }//GEN-LAST:event_applyJButtonActionPerformed

    private void defaultJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultJButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_defaultJButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton applyJButton;
    private javax.swing.JPanel buttonJPanel;
    private javax.swing.JButton closeJButton;
    private javax.swing.JButton connectionJButton;
    private javax.swing.JCheckBox connectionJCheckBox;
    private javax.swing.JButton dataJButton;
    private javax.swing.JCheckBox databaseImportJCheckBox;
    private javax.swing.JComboBox databaseJComboBox;
    private javax.swing.JPanel databaseJPanel;
    private javax.swing.JLabel databaseSupportJLabel;
    private javax.swing.JButton defaultJButton;
    private javax.swing.JTextField filetypeJField;
    private javax.swing.JLabel filetypeJLabel;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.JPanel generalJPanel;
    private javax.swing.JCheckBox generateEIDJCheckBox;
    private javax.swing.ButtonGroup importButtonGroup;
    private javax.swing.JPanel importJPanel;
    private javax.swing.JRadioButton importJRadioButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTabbedPane mainJTabbedPane;
    private javax.swing.JCheckBox packageJCheckBox;
    private javax.swing.JCheckBox pictureJCheckBox;
    private javax.swing.JPanel resourceJPanel;
    private javax.swing.JRadioButton scanJRadioButton;
    private javax.swing.JPanel toolJPanel;
    // End of variables declaration//GEN-END:variables
}
